package com.example.driving.ui;

import android.content.Intent;
import android.os.Bundle;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import androidx.annotation.NonNull;
import androidx.lifecycle.LiveData;
import androidx.lifecycle.Transformations;
import androidx.recyclerview.widget.GridLayoutManager;

import com.bumptech.glide.Glide;
import com.example.driving.R;
import com.example.driving.base.BaseFragment;
import com.example.driving.base.Data;
import com.example.driving.base.OnItemClickListener;
import com.example.driving.databinding.FragmentSubject2Binding;
import com.example.driving.databinding.FragmentSubjectBinding;
import com.example.driving.model.CityBean;
import com.example.driving.model.Subject2Bean;
import com.example.driving.ui.adapter.Subject2Adapter;
import com.example.driving.utils.Api;
import com.example.driving.utils.HttpUtils;
import com.example.driving.utils.JsonUtils;
import com.example.driving.utils.NetUtils;
import com.github.leonardoxh.livedatacalladapter.Resource;
import com.orhanobut.logger.Logger;

import java.util.ArrayList;
import java.util.List;
import java.util.TreeMap;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;


public class Subject2Fragment extends BaseFragment<FragmentSubject2Binding> {
    private FragmentSubject2Binding mBinding;

    private Subject2Adapter subject2Adapter;
    private List<Subject2Bean> data;

    private int subject;

    public Subject2Fragment(int subject) {
        this.subject = subject;
    }

    @Override
    public FragmentSubject2Binding getViewBinding(LayoutInflater inflater, ViewGroup container) {
        mBinding = FragmentSubject2Binding.inflate(inflater, container, false);
        if (subject==3){
            mBinding.textView2.setText("科目三考试项目");
            mBinding.img.setBackgroundResource(R.mipmap.bg_video_head_k3);
        }

        return mBinding;
    }



    @Override
    protected void initView(Bundle savedInstanceState) {
        getVideoList();

    }

    @Override
    protected void initData() {

    }

    public void getVideoList() {

        Call<Data<List<Subject2Bean>>> call = NetUtils.get().getVideoList(subject);

        call.enqueue(new Callback<Data<List<Subject2Bean>>>() {


            @Override
            public void onResponse(Call<Data<List<Subject2Bean>>> call, Response<Data<List<Subject2Bean>>> response) {
                Data<List<Subject2Bean>> listData = response.body();
                if (listData != null) {
                    List<Subject2Bean> subjectList = listData.getData();
                    subject2Adapter = new Subject2Adapter(subjectList);
                    subject2Adapter.setOnItemClickListener(new OnItemClickListener() {
                        @Override
                        public void onItemClick(View view, int position) {
                            Intent intent = new Intent(getContext(), SimpleVideoActivity.class);
                            intent.putExtra("position", position);
                            System.out.println("dafa");
                            System.out.println( subjectList.get(position).getVideourl());
                            intent.putExtra("videoUrl", subjectList.get(position).getVideourl());
                            intent.putExtra("title", subjectList.get(position).getTitle());
                            startActivity(intent);
                        }

                    });
                    mBinding.rvVideo.setAdapter(subject2Adapter);
                    mBinding.rvVideo.setLayoutManager(new GridLayoutManager(getContext(), 2));
                }

            }

            @Override
            public void onFailure(Call<Data<List<Subject2Bean>>> call, Throwable t) {

            }
        });

    }


    @Override
    public void onBaseClick(View v) {

    }




}